import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.metal.MetalSliderUI;


public class YYFrame extends JFrame{
	
	 /**
	 * 
	 */
	private static final long serialVersionUID = -6330929231468260125L;
	
	JSlider controlBar;
	
	
	 public YYFrame(String name, JPanel display){
		this.getContentPane().add(display, BorderLayout.CENTER);
		this.setSize(new Dimension(display.getWidth(), display.getHeight()));

		controlBar = new JSlider(JSlider.HORIZONTAL, 0, 1000, 0);
		controlBar.setMajorTickSpacing(100);
		controlBar.setMinorTickSpacing(50);
		controlBar.setPaintTicks(true);
		//controlBar.setPaintLabels(true);
		
		
		controlBar.setUI(new MetalSliderUI() {
		    protected void scrollDueToClickInTrack(int direction) {
		        // this is the default behaviour, let's comment that out
		        //scrollByBlock(direction);

		        int value = controlBar.getValue(); 

		        if (controlBar.getOrientation() == JSlider.HORIZONTAL) {
		            value = this.valueForXPosition(controlBar.getMousePosition().x);
		        } else if (controlBar.getOrientation() == JSlider.VERTICAL) {
		            value = this.valueForYPosition(controlBar.getMousePosition().y);
		        }
		        controlBar.setValue(value);
		    }
		});
		
		
		this.getContentPane().add(controlBar, BorderLayout.SOUTH);
		this.setTitle(name);
	    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    this.pack();
	    this.setLocationRelativeTo(null);
	    this.setVisible(true);

	}
	 
	public void addChangeListener(ChangeListener l){
		controlBar.addChangeListener(l);
	}
	
	public void addMouseListener(MouseListener mouseListener){
		controlBar.addMouseListener(mouseListener);
	}
	
	public void updatePlayBar(float percent){
		int value = (int) ((float)controlBar.getMaximum() * percent);
		controlBar.setValue(value);
	}
}
